<?php
namespace app\model;
use think\admin\Model;


/**
 * 商家
 * @class PluginAccountUser
 * @package plugin\account\model
 */
class Merchant extends Model
{
    protected $table = "zuju_merchant";

    public function cate()
    {
        return $this->belongsTo(MerchantCate::class, 'cate_id', 'id');
    }

    public function cassette(){
        return $this->hasMany(Cassette::class,'mid')->order('sort desc')->where('status',1);
    }

    public function getIsOpenAttr($value,$data){
         // 获取当前时间
        $currentTime = date('H:i:s');

        // 获取数据库中的 open_time 和 close_time
        $openTime = $data['open_time'];
        $closeTime = $data['close_time'];

        // 判断当前时间是否在营业时间内
        if ($currentTime >= $openTime && $currentTime <= $closeTime) {
            return true; // 营业中
        } else {
            return false; // 未营业
        }
    }

    public function order(){
        return $this->hasMany(Orders::class,'mid');
    }

    public function members(){
        return $this->hasMany(OrderMembers::class,'mid')->order('id desc')->limit(8);
    }
    
}